package me.leon.ext.java

import com.google.common.truth.Truth
import java.io.FileFilter
import org.junit.Test

class FileUtilsTest {
    private val origin = """E:\t"""
    private val dst = """E:\t2"""
    private val originFile = """E:\t\1.txt"""
    private val dstFile = """E:\t\2.txt"""

    @Test
    fun copyOrMoveDir() {

        Truth.assertThat(FileUtils.copyOrMoveDir(origin.toFile(), dst.toFile())).isTrue()
    }

    @Test
    fun copyOrMoveFile() {
        Truth.assertThat(FileUtils.copyOrMoveFile(originFile.toFile(), dstFile.toFile())).isTrue()
    }

    @Test
    fun delete() {
        Truth.assertThat(FileUtils.delete(dstFile.toFile())).isTrue()
    }

    @Test
    fun deleteAllInDir() {
        println(FileUtils.copyOrMoveDir(origin.toFile(), dst.toFile()))
        Truth.assertThat(FileUtils.deleteAllInDir(dst)).isTrue()
    }

    @Test
    fun deleteFilesInDir() {
        //        println(FileUtils.copyOrMoveDir(origin.toFile(), dst.toFile()))
        Truth.assertThat(FileUtils.deleteFilesInDir(dst)).isTrue()
    }

    @Test
    fun deleteFilesInDirWithFilter() {
        println(FileUtils.copyOrMoveDir(origin.toFile(), dst.toFile()))
        Truth.assertThat(
                FileUtils.deleteFilesInDirWithFilter(
                    dst,
                    FileFilter { pathname -> pathname?.extension == "md" }
                )
            )
            .isTrue()
    }

    @Test
    fun listFilesInDir() {
        println(FileUtils.listFilesInDir(origin))
        println(FileUtils.listFilesInDir(origin, true))
    }

    @Test
    fun getFileCharsetSimple() {
        println(FileUtils.getFileCharsetSimple(originFile))
    }

    @Test
    fun getFileLines() {
        println(FileUtils.getFileLines(originFile))
    }

    @Test
    fun getDirSize() {
        println(FileUtils.getDirSize(origin))
    }

    @Test
    fun getFileSize() {
        println(FileUtils.getFileSize(originFile))
    }

    @Test
    fun getFileMD5ToString() {
        println(FileUtils.getFileMD5ToString(originFile))
    }
}
